/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2013-2014 jfinal app. jfapp Group.
 */

define(['adminapp'], function ($app) {
    $app.navactive('wx_account');

    var source = $("#message-template").html();
    var template = Handlebars.compile(source);

    var callback = function(msg) {
        var e = $("#form-body").find("#alert");
        if (e) {
            $(e).remove();
        }
        if (msg.status == "OK") {
            var context = {class : "alert-success", message : msg.message};
            $("#form-body").prepend(template(context));
        } else {
            var context = {class : "alert-success", message : msg.message};
            $("#form-body").prepend(template(context))
        }
    }

    $(function() {
        $app.formvalidator({
            'account.wx_account': {
                required : true
            },
            'account.token': {
                required : true
            },
            'account.appid': {
                required : true
            },
            'account.appsecret': {
                required : true
            }
        }, 'ajaxForm');





        $("#save").click(function() {
            $("#ajaxForm").ajaxSubmit({
                success : callback
            });
        });
    });
});

